package com.qf.android.huihui.adapter.information;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.qf.android.huihui.R;
import com.qf.android.huihui.bean.InformationBean;
import com.qf.android.huihui.common.IClickListern;

/**
 * Created by 韩爽 on 2017/1/6.
 */

public class InformationAdapter extends RecyclerView.Adapter<InformationAdapter.InfoViewHolder> implements View.OnClickListener {
    private InformationBean informationBean;
    private Context context;
    private LayoutInflater inflater;
    private IClickListern listern=null;
    public InformationAdapter(InformationBean informationBean, Context context) {
        this.informationBean = informationBean;
        this.context = context;
        inflater=LayoutInflater.from(context);
    }

    @Override
    public InfoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=inflater.inflate(R.layout.fragment_infomation_recyclerview_item,parent,false);
        view.setOnClickListener(this);
        return new InfoViewHolder(view);
    }

    @Override
    public void onBindViewHolder(InfoViewHolder holder, int position) {
        InformationBean.DataBean.ListBean.HuiZixunBean bean = informationBean.getData().getList().get(position).getHuiZixun();
        holder.itemView.setTag(bean.getUrl());
        Glide.with(context).load(bean.getImageUrl()).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.imageView);
        holder.text_title.setText(bean.getTitle());
        holder.text_content.setText(bean.getSummary());
    }

    @Override
    public int getItemCount() {
        return informationBean.getData().getList()!=null?informationBean.getData().getList().size():0;
    }

    @Override
    public void onClick(View v) {
        if(listern!=null){
            listern.OnItemClick(v,(String)v.getTag());
        }
    }
    public void setMyClickListener(IClickListern listener) {
        this.listern = listener;
    }

    public class InfoViewHolder extends RecyclerView.ViewHolder {
         private ImageView imageView;
         private TextView text_title;
         private TextView text_content;
        public InfoViewHolder(View itemView) {
            super(itemView);
            imageView= (ImageView) itemView.findViewById(R.id.info_image);
            text_title= (TextView) itemView.findViewById(R.id.info_text_title);
            text_content= (TextView) itemView.findViewById(R.id.info_text_content);
        }
    }
}
